# include <cstdio>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include<cstring>
using namespace std;


int main () {
	int sum = 0;
	cin>>sum;
	char A,B;
	int AWin = 0, /*APeace = 0,*/ ADefeat = 0;
	int AQuan[3];
	int BQuan[3];
	memset(AQuan,0,sizeof(AQuan));
	memset(BQuan,0,sizeof(BQuan));

	for(int i = 0 ; i < sum ; ++i) {
		cin>>A>>B;
//		if(A == B) {
//			APeace ++;
//		}

		if((A== 'C' && B == 'B')||
		        (A== 'B' && B == 'J')||
		        (A== 'J' && B == 'C')
		  ) {
			ADefeat++;
			if(B == 'B') {
				BQuan[0]++;
			} else if(B == 'C') {
				BQuan[1]++;
			} else if(B == 'J') {
				BQuan[2]++;
			}
		}

		else if((A== 'C' && B == 'J')||
		        (A== 'B' && B == 'C')||
		        (A== 'J'&& B == 'B')
		       ) {
			AWin++;
			if(A == 'B') {
				AQuan[0]++;
			} else if(A == 'C') {
				AQuan[1]++;
			} else if(A == 'J') {
				AQuan[2]++;
			}
		}

	}

	int AMax = 0,BMax = 0;
	for(int i = 1 ; i < 3 ; ++i) {
		if(AQuan[i] > AQuan[AMax]) {
			AMax = i;
		}

		if(BQuan[i] > BQuan[BMax]) {
			BMax = i;
		}
	}

	cout<<AWin<<" "<<sum-AWin-ADefeat<<" "<<ADefeat<<endl;
	cout<<ADefeat<<" "<<sum-AWin-ADefeat<<" "<<AWin<<endl;
	if(AMax  == 0) {
		cout<<"B"<<" ";
	} else if(AMax  == 1) {
		cout<<"C"<<" ";
	} else if(AMax  == 2) {
		cout<<"J"<<" ";
	}

	if(BMax  == 0) {
		cout<<"B";
	} else if(BMax  == 1) {
		cout<<"C";
	} else if(BMax  == 2) {
		cout<<"J";
	}

//	cout<<endl;
//	for(int i = 0 ; i < 3 ; ++i) {
//		cout<<"AQuan[i] = "<<AQuan[i]<<endl;
//	}
//	cout<<endl;
//	for(int i = 0 ; i < 3 ; ++i) {
//		cout<<"BQuan[i] = "<<BQuan[i]<<endl;
//	}

	return 0;
}
